
var netUtil = require('/../../utils/netUtil.js');
var util = require('/../../utils/util.js');
var app = getApp();
Page({
  data:{
		customerAddressList : null
  },
  onLoad:function(options){
  	
  	var that = this;
  	
  	app.getUserOpedId(function() {
  		
  		var params = {
  			method : 'wechat.wisen.address.userInfo.query',
  			openId : app.globalData.userInfo.openid
  		}
  		
  		netUtil.buildRequest(that,'/wisen/api/wechat/ret',params,{
				
				onPre: function() {
					netUtil.showLoadingDialog(that);
				},
				
				onSuccess: function(resp) {
					console.log(resp);
					
					netUtil.hideLoadingDialog(that);
					
					if(resp.ret == app.globalData.respSuccessCode) {
										
						var customerAddressList = resp.data;
						that.setData({
							customerAddressList : customerAddressList
						});
						
 					} else {
						if(resp.message != undefined && resp.message != null && resp.message != '') {
 							netUtil.showAlertDialog("提示", resp.message, false, "确定", null, null);
 						} else {
 							netUtil.showAlertDialog("提示", "网络请求失败", false, "确定", null, null);
 						}
					}
					
				},
				
				onError: function(res) {
					console.log("fail");
					netUtil.hideLoadingDialog(that);
					netUtil.showAlertDialog("提示", msgCanShow, false, "确定", null, null);
				}
				
			}).send();
  		
  	});
  	
  },
  onReady:function(){
  
  },
  onShow:function(){
    
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },

  onUnload:function(){
    // 页面关闭

  },
  
  deleteAddress : function(e) {
  	
  	var that = this;
  	
  	var code = e.currentTarget.dataset.code;
  	
  	var params = {
  		method : 'wechat.wisen.address.userInfo.delete',
  		openId : app.globalData.userInfo.openid,
  		data : {
  			code : code
  		}
  	};
  	
  	netUtil.buildRequest(that,'/wisen/api/wechat/ret',params,{
				
			onPre: function() {
				netUtil.showLoadingDialog(that);
			},
				
			onSuccess: function(resp) {
						
				netUtil.showAlertDialog("提示", "删除成功", false, "确定", null, function() {
					that.onLoad();
				});
			},
				
			onError: function(res) {
				console.log("fail");
				netUtil.hideLoadingDialog(that);
				netUtil.showAlertDialog("提示", msgCanShow, false, "确定", null, null);
			}
				
		}).send();
  	
  },
  
  toAddAddressPage : function() {
  	wx.navigateTo({
				url: '/pages/address-update/address-update'
		});
  },
  
  toUpdateAddressPage : function(e) {
  	
  	var code = e.currentTarget.dataset.code;
  	var address = e.currentTarget.dataset.address;
  	var phoneNum = e.currentTarget.dataset.phonenum;
  	var receiver = e.currentTarget.dataset.receiver;
  	
  	wx.navigateTo({
				url: '/pages/address-update/address-update?address=' + address + "&code=" + code + "&phoneNum=" + phoneNum + "&receiver=" + receiver
		});
  }
	
})